<?php

namespace app\models\search;

use app\models\CrmConfig;
use yii\base\Model;
use yii\data\ActiveDataProvider;

class CrmConfigSearch extends CrmConfig
{
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['name','indicate', 'type','params'], 'safe'],
        ];
    }

    public function scenarios()
    {
        return Model::scenarios();
    }

    /**
     * @param array $传递的参数，数组
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = CrmConfig::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        //设置前端传来的需要查询的数据
        $this->load($params,"");
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere([
//            'id' => $this->id,
        ]);
        $query->limit($params['limit']);
        $query->offset($params['limit']*($params['page']-1));
        $query
            ->andFilterWhere(['=', 'type', $params['search']['type']]);//接听电话

        return $dataProvider;
    }
}
